<?xml version="1.0" encoding="utf-8" ?>
[#include "/WEB-INF/pages/common/taglibs.ftl"]
[@c.url var="backUrl" value='/manage/Role_list.action' scope="page"]
[/@c.url]
[#macro _script]
	<link rel="stylesheet" href="[@c.url value='/js/plugins/jquery-ztree/css/zTreeStyle/zTreeStyle.css'/]" type="text/css">
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery-ztree/js/jquery.ztree.core-3.1.js'/]"></script>
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery-ztree/js/jquery.ztree.excheck-3.1.min.js'/]"></script>
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.alerts.js'/]"></script>
	<script type="text/javascript" src="[@c.url value='/js/plugins/jquery.form.js'/]"></script>
	<script type="text/javascript">
		var base = (function(){
			// 事件绑定
			function _addEventListeners() {
        		$('#roleSubmit').click(function(){
        			var form = $('#roleFunctionForm');
        			form.submit();
        			return false;
        		})
				$('#roleFunctionForm').submit(function() {
				 	var options = { 
				 		timeout:'3000',
				 		data : {ajax:true},
				 		success: function(responseText, statusText, xhr, $form){
				 			if (statusText == "error") {
				 				jAlert("${action.getText('role.function.updated.error')}", "提示"); 
				 			}
				 			if (statusText == "success") {
				 				jAlert("${action.getText('role.function.updated.success')}", "提示"); 
				 			}
				 		}
				 	}
				 	var params = {};
				 	var zTree = $.fn.zTree.getZTreeObj("functionTree"),
        			nodes = zTree.getCheckedNodes();
        			for (var n in nodes) {
        				params['roleFunctionList['+n+'].siteFunctionId'] = nodes[n].originalId;
        			}
        			options.data = params;
			        $(this).ajaxSubmit(options); 
			 
			        return false; 
			    }); 
			}
	
			// 页面渲染
			function _treeRender () {
				var zNodes =[#include "/WEB-INF/pages/manage/Role/tree.ftl"];
	            var setting = {
						data: {
							simpleData: {
								enable: true
							}
						}, 
						check: {
							enable: true
						}, 
						view: {
							// 渲染树
							addDiyDom: function (treeId, treeNode) {
								// 根节点以外的父节点
								//if (treeNode.pId != null) {
								//	$('#' + treeNode.tId).append("<a href='javascript:void(0);' onClick=\"return base.rmDir('" + treeNode.id + "')\">[删除]</a>");
								//}
							}
						},
						callback: {
							onClick: function(event, treeId, treeNode, clickFlag){
								//var isParent = treeNode.isParent;
								//var id = treeNode.id;
								//$.get(base.config.url, {'id':id, 'ajax':true, 'piece':true}, function(data){
				                //	$('#categoryTableList').html(data);
				                //	_addEventListeners();
				                //});
							}
						}
					};
				$.fn.zTree.init($("#functionTree"), setting, zNodes);
			}
			return {
                config: {
                	url : null,
                    theme: null
                },
                init: function () {
                	_treeRender();
                	_addEventListeners();
                }
			}
		}());
		
		$(function(){
			var link = "[@c.url value='/manage/Role_list.action?currentPage=${currentPage}' /]";
			base.config.theme = getTheme();
			base.config.url = link;
            //Initializing the form
			base.init();
		})
	</script>
[/#macro]
[#if piece==true]
	[@_script /]
	<!--设置提交行为-->
	[#assign act="save" /]
	<!--设置table渲染到指定ID节点-->
	[#include "/WEB-INF/pages/manage/Role/_roleList.ftl"]
[#else]
	<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title>Insert title here</title>
		<meta name="menu" content="AdminMenu"/>
		<meta name="heading" content="heading"/>
		[@_script /]
	</head>
	<body id="body">
        <div class="contenttitle radiusbottom0">
        	<h2 id="vertical" class="form"><span>角色功能管理</span></h2>
        </div><!--contenttitle-->
        <br>
        <!-- START OF VERTICAL WIZARD -->
		<form id="roleFunctionForm" action="[@c.url value='/manage/Role_enable.action'][@c.param name="backurl" value="${currentUrl}"/][/@c.url]" method="post" class="">
			<div class="wizard verwizard">
				<!--设置提交行为-->
				[#assign act="save" /]
				<ul class="verticalmenu anchor" id="roleList">
					[#list roleList as role]
						<li><a class="role [#if (id==null && role_index==0) || id==role.id]done[/#if]" cid="${role.id}" href="[@c.url value='/manage/Role_auth.action?id=${role.id}' /]"><span class="label">${role.name}</span></a>
					[/#list]
				</ul>
				<!--#wiz1step3_1-->
				<!--#wiz1step3_2-->
				<!--#wiz1step3_3-->

				<div class="stepContainer" style="height: 365px;">
					<div class="formwiz content" style="display: block;">
						<div id="roleFunctionTree" style="height:350px">
							<div class="widgetcontent announcement">
								<ul id="functionTree" class="ztree" style="height:350px;overflow:auto;"></ul>
							</div>
						</div>
					</div>
				</div>
				<div class="actionBar">
					<div class="loader">Loading</div>
					[#if id==null]
						[#assign id="${roleList.get(0).id}"/]
					[#else]
						[#assign id="${id}"]
					[/#if]
					<div><input type="hidden" value="${id}" name="id"/></div>
					<span class="loading" style="display:none;"><img alt="" src="[@c.url value='/images/loaders/loader3.gif'/>"></span>
					<a style="float:left;" href="javascript:;" class="buttonFinish" id="roleSubmit" >提交</a>
					<a style="float:left;" href="[@c.url value='/manage/Role_edit.action'][@c.param name="id" value="${id}"/][@c.param name="backurl" value="${backUrl}"/][/@c.url]"	class="buttonPrevious">编辑</a>
					<a style="float:left;" href="[@c.url value='/manage/Role_create.action'/]"	class="buttonNext" id="roleCreate">创建</a>
					<!--<a href="javascript:;"	class="buttonPrevious buttonDisabled">Previous</a>-->
				</div>
			</div>
			<!--#wizard-->
		</form>
		<br />
	</body>
	</html>
[/#if]